﻿using System;
using System.Collections.Generic;
using System.Linq;
using Skyhook.Core;
using Microsoft.Xna.Framework;

namespace Skyhook.Isometry
{
    public class IsometryEngine : IObjectsEngine
    {
        World World = null;
        WorldObjectFactory Factory = null;
        WorldOnScreenView pOnScreenView = null;

        public IsometryEngine()
        {
        }

        public void CreateWorld(int width, int height)
        {
            World = new World(width, height);
            Factory = new WorldObjectFactory(World.TileMap);
            
        }

        public void CreateView(int viewwidth, int viewheight, float tilewidth = 64.0f, float tileheight = 32.0f)
        {
            CoordinatesConverter.SetTileSize(tilewidth, tileheight);         
            pOnScreenView = new WorldOnScreenView(World, viewwidth, viewheight, tilewidth, tileheight);
        }

        public IObjectController CreateObject(ILogic logic, IVisual visual)
        {
            if (World == null)
            {
                return null;
            }
            WorldObject worldobject = Factory.CreateObject();
            visual.SetScreenPosition(worldobject.CreateScreenPosition());
            worldobject.InsertContent(logic,visual);
                        
            return worldobject.CreateController();
        }

        public IOnScreenView OnScreenView
        {
            get
            {
                return pOnScreenView;
            }
        }

        public int ObjectsCount
        {
            get
            {
                return World.ObjectsCount;
            }
        }
    }
}
